package com.zhou.core.logana.handle.json.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhou.core.logana.LogRecord;
import com.zhou.core.logana.enums.RepositoryKeyEnum;
import com.zhou.core.logana.handle.json.AbstractJsonLogAnaHandler;
import com.zhou.core.os.v2_sigar.FormatUtil;
import com.zhou.core.os.v2_sigar.SigarService;
import com.zhou.core.os.v2_sigar.entity.*;
import com.zhou.core.os.v3_oshi.OSHIService;
import com.zhou.core.os.v3_oshi.entity.OSHISystem;
import com.zhou.util.StringUtils;
import com.zhou.util.TimeUtils;
import org.hyperic.sigar.SigarException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Timestamp;
import java.util.List;

/**
 *
 */

public class OSHITotalJsonLogAnaHandlerImpl extends AbstractJsonLogAnaHandler {
    private Logger logger  = LoggerFactory.getLogger(OSHITotalJsonLogAnaHandlerImpl.class);
    @Override
    public String repositoryKey() {
        return RepositoryKeyEnum.OSHI_TOTAL.name();
    }

    @Override
    public LogRecord handle(Object... params) {
        String key = TimeUtils.formatNoSpr(TimeUtils.now());
        jsonObject.put("value", JSON.toJSONString(_handle(params)));
        jsonObject.put("datetime", key);
        LogRecord record = new LogRecord();
        record.setRepositoryKey(repositoryKey());
        record.setValue(jsonObject.toJSONString());
        record.setKey(key);

        return record;
    }

    public OSHISystem _handle(Object... params) { ;
        OSHISystem system = OSHIService.getInstance().generateOSHISystem();
        return system;
    }


    /**
     * 30秒后执行，每隔5分钟执行, 单位：ms。
     * 获取监控进程
     */
//    @Scheduled(initialDelay = 28 * 1000L, fixedRate = 300 * 1000)
   /* public void appInfoListTask() {
        JSONObject jsonObject = new JSONObject();
        LogInfo logInfo = new LogInfo();
        Timestamp t = FormatUtil.getNowTime();
        logInfo.setHostname(commonConfig.getBindIp()+"：Agent获取进程列表错误");
        logInfo.setCreateTime(t);
        try {
            JSONObject paramsJson = new JSONObject();
            paramsJson.put("hostname",commonConfig.getBindIp());
            String resultJson = restUtil.post(commonConfig.getServerUrl()+"/wgcloud/appInfo/agentList",paramsJson);
            if(resultJson!=null){
                JSONArray resultArray  = JSONUtil.parseArray(resultJson);
                appInfoList.clear();
                if(resultArray.size()>0){
                    appInfoList = JSONUtil.toList(resultArray, AppInfo.class);
                }
            }
        }  catch (Exception e) {
            e.printStackTrace();
            logInfo.setInfoContent(e.toString());
        }finally {
            if(!StringUtils.isEmpty(logInfo.getInfoContent())){
                jsonObject.put("logInfo",logInfo);
            }
            restUtil.post(commonConfig.getServerUrl()+"/wgcloud/agent/minTask",jsonObject);
        }
    }
*/


}
